package com.zhuzi.config;

import com.zhuzi.webservice.*;
import com.zhuzi.webservice.impl.CatServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author zhuzi
 * 2022/8/2 16:36
 */
@Configuration
public class WSConfig {

    //默认servlet路径/*,如果覆写则按照自己定义的来
    @Bean
    public ServletRegistrationBean disServlet() {
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFServlet(), "/Service/*");
        return servletRegistrationBean;
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    //终端路径
    /*@Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), webService());
        endpoint.publish("/test");
        return endpoint;
    }*/

    @Bean
    public TestService testService() {
        return new TestServiceImpl();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), testService());
        endpoint.publish("/testService");
        return endpoint;
    }


    @Bean
    public Endpoint endpoint2() {
        // 如果 此处的 parseXml 是 new ，则在CatServiceImpl  里面无法使用@Autowired注入对象(spring管理的对象)
        EndpointImpl endpoint = new EndpointImpl(springBus(), new CatServiceImpl());
        endpoint.publish("/CatService");
        return endpoint;
    }

    @Bean
    public ParseXml parseXml() {
        return new ParseXmlRelaImpl();
    }

    @Bean
    public UserServiceImpl userServiceImpl() {
        return new UserServiceImpl();
    }

    @Bean
    public Endpoint endpointUserService() {
        // 如果 此处的 parseXml 是 new ，则在CatServiceImpl  里面无法使用@Autowired注入对象(spring管理的对象)
        EndpointImpl endpoint = new EndpointImpl(springBus(), userServiceImpl());
        endpoint.publish("/user");
        return endpoint;
    }

    /**
     * 82
     */
    @Bean
    public Endpoint endpointParseXml() {
        // 如果 此处的 parseXml 是 new ，则在CatServiceImpl  里面无法使用@Autowired注入对象(spring管理的对象)
        EndpointImpl endpoint = new EndpointImpl(springBus(), parseXml());
        endpoint.publish("/parseXml");
        return endpoint;
    }

}
